package com.asfo.demo.comm;

import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;

public class ResultObject {
    private Long resultCode;
    private String resultMsg;

    private String object;

    public ResultObject(Long resultCode, String resultMsg,Object object) {
        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
        this.object= JSON.toJSONString(object);
    }
    public static ResultObject buildSuccess(){
        return buildSuccess("成功",null);
    }
    public static ResultObject buildSuccess(Object object){
        return buildSuccess("成功",object);
    }

    public static ResultObject buildSuccess(String resultMsg,Object object){
        return new ResultObject(0L, StringUtils.isEmpty(resultMsg)?"成功":resultMsg,object);
    }

    public static ResultObject buildFail(){
        return buildFail("失败");
    }

    public static ResultObject buildFail(String resultMsg){
        return new ResultObject(1L, StringUtils.isEmpty(resultMsg)?"失败":resultMsg,null);
    }

    public Long getResultCode() {
        return resultCode;
    }

    public void setResultCode(Long resultCode) {
        this.resultCode = resultCode;
    }

    public String getResultMsg() {
        return resultMsg;
    }

    public void setResultMsg(String resultMsg) {
        this.resultMsg = resultMsg;
    }

    public String getObject() {
        return object;
    }

    public void setObject(String object) {
        this.object = object;
    }

    @Override
    public String toString() {
        return "ResultObject{" +
                "resultCode=" + resultCode +
                ", resultMsg='" + resultMsg + '\'' +
                '}';
    }
}
